package com.jd.finance.core.controller.admin;


import com.jd.finance.core.service.PhotoService;
import com.jd.finance.core.service.impl.AdminUtilsServiceImpl;
import com.jd.finance.result.BaseResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.yaml.snakeyaml.events.Event;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author LiQingBo
 * @since 2022-05-19
 */
@Api(tags = "banner管理页")
@RestController
@Slf4j
@RequestMapping("/admin/core/bannerCenter")
public class AdminPhotoController {

    @Resource
    private AdminUtilsServiceImpl adminUtilsService;

    @Autowired
    private PhotoService photoService;

    @ApiOperation("查询所有banner图")
    @GetMapping("/getAllBannerPhoto")
    public BaseResult getAllBannerPhoto(Integer uid) {
        if (uid == null) {
            log.error("id为空C");
            return BaseResult.error().message("id为空");
        }

        if (!adminUtilsService.isInformation(uid)) {
            log.error("无访问权限C");
            return BaseResult.error().message("无访问权限");
        }

        return photoService.getAllBannerPhoto();
    }

    @ApiOperation("添加banner图")
    @GetMapping("/insertBannerPhoto")
    public BaseResult insertBannerPhoto(Integer uid, String photoPath, String photoUrl, HttpServletRequest request) {
        if (uid == null) {
            log.error("传入id为空");
            return BaseResult.error().message("传入id为空");
        }
        if (StringUtils.isAllBlank(photoPath, photoUrl)) {
            log.error("传入信息为空");
            return BaseResult.error().message("传入信息为空");
        }
        if (!adminUtilsService.isInformation(uid)){
            log.error("无访问权限");
            return BaseResult.error().message("无访问权限");
        }

        return photoService.insertBannerPhoto(uid, photoPath, photoUrl, request);

    }

    @ApiOperation("删除banner图")
    @GetMapping("/deleteBannerPhoto")
    public BaseResult deleteBannerPhoto(Integer uid, Integer bannerId,HttpServletRequest request) {
        if (uid == null || bannerId == null) {
            log.error("传入id为空");
            return BaseResult.error().message("传入id为空C");
        }
        if (!adminUtilsService.isInformation(uid)){
            log.error("无访问权限C");
            return BaseResult.error().message("无访问权限C");
        }

        return photoService.deleteBannerPhoto(uid, bannerId, request);

    }

    @ApiOperation("修改banner排序序号")
    @GetMapping("/updateBannerSeq")
    public BaseResult updateBannerSeq(Integer uid, Integer photoId, Integer bannerNumber, HttpServletRequest request) {
        if (uid == null || bannerNumber == null){
            return BaseResult.error().message("参数为空");
        }

        if (!adminUtilsService.isInformation(uid)){

            log.error("无访问权限C");
            return BaseResult.error().message("无访问权限C");
        }

        return photoService.updateBannerSeq(uid, photoId, bannerNumber, request);

    }





}

